<?php

use Phinx\Db\Adapter\MysqlAdapter;
use think\migration\Migrator;
use think\migration\db\Column;

class CreateTableAdminLog extends Migrator
{
    public function up()
    {
        if (!$this->hasTable('admin_log')) {
            $table = $this->table('admin_log', ['engine' => 'MyISAM'])
                ->setId('id')
                ->setPrimaryKey('id')
                ->setComment('管理员登录表');
            $table->addColumn('admin_id', 'integer', ['limit' => 11, 'null' => false, 'comment' => '管理员id'])
                ->addColumn('add_time', 'integer', ['limit' => 11, 'null' => false, 'default' => '0', 'comment' => '登录时间'])
                ->addColumn('admin_ip', 'string', ['limit' => 50, 'null' => false, 'default' => '', 'comment' => '登录ip'])
                ->addColumn('type', 'integer', ['limit' => MysqlAdapter::INT_TINY, 'null' => false, 'default' => '0', 'comment' => '0-登录失败 1-登录成功 2-操作'])
                ->addColumn('content', 'string', ['limit' => 500, 'null' => false, 'default' => '', 'comment' => '操作内容'])
                ->create();
        }
    }

    public function down()
    {
        if ($this->hasTable('admin_log')) {
            $this->dropTable('admin_log');
        }
    }
}
